#include "AutoProg.h"
#include "flash_manager.h"
#include "flash_decoder.h"
#include "target_board.h"
#include "DAP_config.h"

void auto_prog(void)
{
    FirmwareInfo **bins;
    const flash_intf_t *target = flash_intf_target;
    bins = FirmwareBins;
    target->init();
    if (ERROR_SUCCESS != target->erase_chip())
    {
        target->uninit();
        target->init();
        target->erase_chip();
    }

    for (; *bins; bins++)
    {
        FirmwareInfo *bin = *bins;
        target->flash_algo_set(bin->startaddr);
        target->program_page(bin->startaddr, bin->data, bin->length);
    }
    target->init();
    target->uninit();
    LED_CONNECTED_OUT(0);
}
